package com.ruoyi.project.WebMoudle.vipCoupon.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.WebMoudle.vipCoupon.domain.VipCoupon;
import com.ruoyi.project.WebMoudle.vipCoupon.service.IVipCouponService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 会员优惠券Controller
 * 
 * @author ruoyi
 * @date 2020-07-09
 */
@Controller
@RequestMapping("/vipCoupon/vipCoupon")
public class VipCouponController extends BaseController
{
    private String prefix = "vipCoupon/vipCoupon";

    @Autowired
    private IVipCouponService vipCouponService;

    @RequiresPermissions("vipCoupon:vipCoupon:view")
    @GetMapping()
    public String vipCoupon()
    {
        return prefix + "/vipCoupon";
    }

    /**
     * 查询会员优惠券列表
     */
    @RequiresPermissions("vipCoupon:vipCoupon:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(VipCoupon vipCoupon)
    {

        startPage();
        List<VipCoupon> list = vipCouponService.selectVipCouponList(vipCoupon);
        return getDataTable(list);
    }

    /**
     * 导出会员优惠券列表
     */
    @RequiresPermissions("vipCoupon:vipCoupon:export")
    @Log(title = "会员优惠券", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(VipCoupon vipCoupon)
    {
        List<VipCoupon> list = vipCouponService.selectVipCouponList(vipCoupon);
        ExcelUtil<VipCoupon> util = new ExcelUtil<VipCoupon>(VipCoupon.class);
        return util.exportExcel(list, "vipCoupon");
    }

    /**
     * 新增会员优惠券
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存会员优惠券
     */
    @RequiresPermissions("vipCoupon:vipCoupon:add")
    @Log(title = "会员优惠券", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(VipCoupon vipCoupon)
    {
        return toAjax(vipCouponService.insertVipCoupon(vipCoupon));
    }

    /**
     * 修改会员优惠券
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        VipCoupon vipCoupon = vipCouponService.selectVipCouponById(id);
        mmap.put("vipCoupon", vipCoupon);
        return prefix + "/edit";
    }

    /**
     * 修改保存会员优惠券
     */
    @RequiresPermissions("vipCoupon:vipCoupon:edit")
    @Log(title = "会员优惠券", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(VipCoupon vipCoupon)
    {
        return toAjax(vipCouponService.updateVipCoupon(vipCoupon));
    }

    /**
     * 删除会员优惠券
     */
    @RequiresPermissions("vipCoupon:vipCoupon:remove")
    @Log(title = "会员优惠券", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(vipCouponService.deleteVipCouponByIds(ids));
    }
}
